#include "stdafx.h"
#include "base/system/process_walker.h"

ProcessWalker::ProcessWalker()
{

}

ProcessWalker::~ProcessWalker()
{

}

PROCESSENTRY32 * ProcessWalker::Get()
{
    return &m_oProcessEntry;
}

BOOL ProcessWalker::Start(DWORD nPid)
{
    m_hSnapshot.Set(::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, nPid));
    if(INVALID_HANDLE_VALUE == m_hSnapshot) {
        return FALSE;
    }

    memset(&m_oProcessEntry, 0, sizeof(PROCESSENTRY32));
    m_oProcessEntry.dwSize = sizeof(PROCESSENTRY32);
    return ::Process32First(m_hSnapshot, &m_oProcessEntry);
}

BOOL ProcessWalker::Next()
{
    return ::Process32Next(m_hSnapshot, &m_oProcessEntry);
}